<?php
namespace Admin\Controller;
use Think\Controller;

class ActivityController extends CommonController{

	//活动信息列表
	public function lists(){
		$activity_list = D("Activity")->getActivityList();
		$this->assign('activity',$activity_list);
		$this->display();
		dump($activity_list);

	}


	//添加活动信息
	
	public function add(){

		if(IS_POST){

		//dump($_POST);	
			$upload = new \Think\Upload();// 先实例化上传类 
			$upload->maxSize   = 3145728 ;// 设置附件上传大小 
			$upload->exts      = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
			$upload->savePath  = './logo/'; // 设置附件上传目录  
			$upload->rootPath  = './Upload/';
			// 上传文件     
			$info   =   $upload->upload();  
			/*echo"<pre>";
			print_r($info);
			dump($info);*/
			if(!$info) {
			// 上传错误提示错误信息        
			$this->error($upload->getError());
			}else{
			// 上传成功        
			$this->success('上传成功！');  
			}

			$data =array();
			$data['title']=I("title","",'');
			$data['money']=I("money",0,'float');   //
			$lu =date("Y-m-d");
			$data['img']="$lu/".$info['img']['savename'];
			$data['number']=I("number"); //报名人数
			$data['mobile']=I("mobile");
			$data['trait']=I("trait"); //类型
			$data['email']=I("email");
			$data['address']=I("address");
			$data['companyname']=I("companyname","",''); //活动名称

			$des  = html_entity_decode($_POST[codeDes]);//html_entity_decode   htmlspecialchars
			$des2 = html_entity_decode($_POST[codeDes]);
			$des3 = html_entity_decode($_POST[codeDes]);
			$des4 = html_entity_decode($_POST[codeDes]);

			$data['des']=I("editor",'');  //
			$data['des2']=I("editor2",'');
			$data['des3']=I("editor3",'');
			$data['des4']=I("editor4",'');
			
			
			$data['create_time'] = NOW_TIME;


			


			D("activity")->add($data);
			//dump($data);
		
			header("Location:".U("activity/lists"));

		}else{

		$this->display();
		}
	}


	//散工信息编辑
	public function edite(){
		if(IS_POST){
			$data =array();
			$data['title'] = I("title","");
			$data['money']  = I("money","");
			$uid=I('get.id/d'); // 如果不存在$_GET['id'] 则返回0
			M("activity")->where("id ='{$uid}'")->save($data);

			//dump($data);
			//dump($uid);

			$this->redirect('Activity/lists');
		


		}else{
			$uid = I("id",0,"int");
			$activity_info =M("activity")->where("id='{$uid}'")->find();
			//dump($user_info);
			//dump($uid);
			$this->assign("activity_info",$job_info);
			$this->display();		
		}
	}



	//散工信息删除,已经实现
	public function delete(){
		$uid = I('id/d');
		M("activity")->where("id='{$uid}'")->delete();
		//dump($uid);
		$this->redirect('Activity/lists');	


	}	



//结束
}